﻿using System;
using System.Numerics;

class CatalanNumbers
{
    static void Main()
    {
        //Exercise 9-10.
        //In the combinatorial mathematics, the Catalan numbers are calculated by the following formula: (in the presentation)
        //Write a program to calculate the Nth Catalan number by given N.

        Console.Write("Enter N:  ");
        uint number = uint.Parse(Console.ReadLine());        
        BigInteger resultPowerTwo = 2 * number;
        BigInteger result = 1;
        BigInteger resultPlusOne = number + 1;

        for (uint k = 1; k < 2 * number; k++)
        {
            resultPowerTwo = resultPowerTwo * k;
        }
       
        for (uint i = 1; i <= number; i++)
        {
            result = result * i;           
        }        

        for (uint j = 1; j <= number; j++)
        {
            resultPlusOne = resultPlusOne * j;
        }
        
        BigInteger catalan = (resultPowerTwo) / (resultPlusOne * result);

        Console.WriteLine(catalan);

    }
}

